<?php

namespace app\api\controller;

use \think\Request;
use app\common\business\user\Hd as hdBn;
use app\common\business\http\wechat\Wechat as wechatHttp;
class Hd extends \app\common\controller\HomeBase {

    /**
     *
     * 大转盘概率
     *
     * */
    public function getrandprize() {
        try {
            $user_id = $this->_validLogin();
            $params = input();
            $validate = Validate('Hd');
            $params = $validate->scene('getrandprize')->check($params);
            if (!$params) {
                exception($validate->getError(), 10000003);
            }
            $params['user_id'] = $user_id;
            $data = hdBn::get_rand($params);
            $this->_echoSuccessMessage('success', $data);
        } catch (\Exception $e) {
            $this->_echoErrorMessage($e->getMessage(), $e->getCode());
        }
    }

    /**
     *
     * 大转盘概率
     *
     * */
    public function prizetotal() {
        try {
            $user_id = $this->_validLogin();
            $params = input();

            $validate = Validate('Hd');
            $params = $validate->scene('getrandprize')->check($params);
            if (!$params) {
                exception($validate->getError(), 10000003);
            }

            $params['user_id'] = $user_id;
            $data = hdBn::prizetotal($params);
            $this->_echoSuccessMessage("success", $data);
        } catch (\Exception $e) {
            $this->_echoErrorMessage($e->getMessage(), $e->getCode());
        }
    }

    /**
     *
     * 跑马灯
     *
     * */
    public function runninglight() {
        try {
            $user_id = $this->_isLogin();
            $params = input();
            $validate = Validate('Hd');
            $params = $validate->scene('getrandprize')->check($params);
            if (!$params) {
                exception($validate->getError(), 10000003);
            }
            $params['user_id'] = $user_id;
            $data = hdBn::runninglight($params);
            $this->_echoSuccessMessage("success", $data);
        } catch (\Exception $e) {
            $this->_echoErrorMessage($e->getMessage(), $e->getCode());
        }
    }

    /**
     *
     * 大转盘用户的奖品
     *
     * */
    public function userprize() {
        try {
            $user_id = $this->_validLogin();
//            $user_id=12;
            $params = input();
            $validate = Validate('Hd');
            $params = $validate->scene('getrandprize')->check($params);
            if (!$params) {
                exception($validate->getError(), 10000003);
            }
            $params['user_id'] = $user_id;
            $data = hdBn::userprize($params);
            $this->_echoSuccessMessage("success", $data);
        } catch (\Exception $e) {
            $this->_echoErrorMessage($e->getMessage(), $e->getCode());
        }
    }

    /*
     * 红包雨统计当场获得的奖品
     *
     * */

    public function prizesum() {
        try {
            $user_id = $this->_validLogin();
            $params = input();
            $params = $this->validate($params, 'Hd.getrandprize');
            $params['user_id'] = $user_id;
            $data = hdBn::prizesum($params);
            $this->_echoSuccessMessage("success", $data);
        } catch (\Exception $e) {
            $this->_echoErrorMessage($e->getMessage(), $e->getCode());
        }
    }

    /**
     *
     * 判断是否是第一次抽奖
     *
     * */
    public function isfirsttime() {
        try {
            $user_id = $this->_isLogin();
            $params = input();
            $validate = Validate('Hd');
            $params = $validate->scene('getrandprize')->check($params);
            if (!$params) {
                exception($validate->getError(), 10000003);
            }
            $params['user_id'] = $user_id;
            $data = hdBn::isfirsttime($params);
            $this->_echoSuccessMessage("success", $data);
        } catch (\Exception $e) {
            $this->_echoErrorMessage($e->getMessage(), $e->getCode());
        }
    }

    /**
     *
     * 服务器时间+抽奖信息
     *
     * */
    public function randprizeInfo() {
        try {
            $user_id = $this->_isLogin();
            $params = input();
            $validate = Validate('Hd');
            $params = $validate->scene('getrandprize')->check($params);
            if (!$params) {
                exception($validate->getError(), 10000003);
            }
            $params['user_id'] = $user_id;
            $data = hdBn::randprizeInfo($params);
            $this->_echoSuccessMessage("success", $data);
        } catch (\Exception $e) {
            $this->_echoErrorMessage($e->getMessage(), $e->getCode());
        }
    }

    /**
     *
     * 服务器时间+抽奖信息
     *
     * */
    public function wxshareapi() {
        try { 
            $params = input();   
            $JsApipub = new \app\extra\WeixinSDK\V3\JsApipub();
            $backurl =isset($_SERVER['HTTP_REFERER'])?$_SERVER['HTTP_REFERER']:'https://qhimg.qiu7.net/sjb_duobao/index26.htm';
            $data = $JsApipub->getjsapistr($backurl);
         
            $this->_echoSuccessMessage("success", $data);
        } catch (\Exception $e) {
            $this->_echoErrorMessage($e->getMessage(), $e->getCode());
        }
    }

}
